home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 November: Tool Chest / Dev.CD Nov 99 TC.toast / What's New? / Sample Code / Overview / Win2MacCounterSamples / 6. CounterAbout / source / CCounterApp.cp next >
Encoding:
Text File  |  1999-09-20  |  4.2 KB  |  153 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        CCounterApp.cp
  3.  
  4.     Contains:    Sample code to accompany Chapter 12 of 
  5.                 "An Introduction to Macintosh Programming for Windows Programmers".
  6.                 
  7.     Written by:    Worldwide Developer Technical Support
  8.  
  9.     Copyright:    1999 Apple Computer, Inc., All Rights Reserved
  10.  
  11.       You may incorporate this sample code into your applications without
  12.       restriction, though the sample code has been provided "AS IS" and the
  13.       responsibility for its operation is 100% yours.  However, what you are
  14.       not permitted to do is to redistribute the source as "DSC Sample Code"
  15.       after having made changes. If you're going to re-distribute the source,
  16.      we require that you make it clear in the source that the code was
  17.     descended from Apple Sample Code, but that you've made changes.
  18.     
  19. */
  20.  
  21. #include "CCounterApp.h"
  22. #include "CounterConstants.h"
  23. #include "CCounterDocument.h"
  24. #include <LSIOUXAttachment.h>
  25. #include <iostream.h>
  26.  
  27. #include <LStaticText.h>
  28. #include <LIconPane.h>
  29. #include <LActiveScroller.h>
  30.  
  31. #include <LGrowZone.h>
  32. #include <LWindow.h>
  33. #include <PP_Messages.h>
  34. #include <PP_Resources.h>
  35. #include <PPobClasses.h>
  36. #include <UDrawingState.h>
  37. #include <UMemoryMgr.h>
  38. #include <URegistrar.h>
  39. #include <UModalDialogs.h>
  40.  
  41. #include <UControlRegistry.h>
  42. #include <UGraphicUtils.h>
  43. #include <UEnvironment.h>
  44.  
  45. #ifndef __APPEARANCE__
  46. #include <Appearance.h>
  47. #endif
  48.  
  49. #include <Sound.h>
  50. #include <ToolUtils.h>
  51.  
  52. // ===========================================================================
  53. int main()
  54. {
  55.     SetDebugThrow_(debugAction_Alert);
  56.     SetDebugSignal_(debugAction_Alert);
  57.     InitializeHeap(3);                    // allocate 3 Master Pointer blocks
  58.     UQDGlobals::InitializeToolbox(&qd);
  59.     UEnvironment::InitEnvironment();
  60.     new LGrowZone(20000);            // For low memory situations.
  61.     CCounterApp    theApp;            // stack allocation
  62.     theApp.Run();
  63.     return 0;
  64. }
  65.  
  66. // ---------------------------------------------------------------------------
  67. CCounterApp::CCounterApp()
  68. {
  69.     if ( UEnvironment::HasFeature( env_HasAppearance ) ) {
  70.         ::RegisterAppearanceClient();
  71.     }
  72.     RegisterAllPPClasses();    // functions to create core PowerPlant classes
  73.     UControlRegistry::RegisterClasses();    // Appearance Manager/GA classes
  74.     RegisterClass_(LActiveScroller);
  75.     AddAttachment(new LSIOUXAttachment);    // Use SIOUX Attachment
  76. }
  77.  
  78.  
  79. // ---------------------------------------------------------------------------
  80. CCounterApp::~CCounterApp()
  81. {
  82. }
  83.  
  84. // ---------------------------------------------------------------------------
  85. //    This function lets you do something when the application starts up
  86. //    without a document.
  87. void
  88. CCounterApp::StartUp()
  89. {
  90.     ObeyCommand(cmd_New, nil);
  91. }
  92.  
  93. // ---------------------------------------------------------------------------------
  94. void
  95. CCounterApp::OpenDocument(FSSpec* inMacFSSpec )
  96. {
  97.     LDocument* theDoc = LDocument::FindByFileSpec(*inMacFSSpec);
  98.     if (theDoc != nil) {                // Document is already open
  99.         theDoc->MakeCurrent();            // Make it the current document
  100.     } else {                            // Make a new Document
  101.         theDoc = new CCounterDocument(this, inMacFSSpec);
  102.     }
  103. }
  104.  
  105. // ---------------------------------------------------------------------------------
  106. LModelObject*
  107. CCounterApp::MakeNewDocument()
  108. {
  109.     FSSpec* spec = nil;
  110.     return new CCounterDocument(this, spec);
  111. }
  112.  
  113. // ---------------------------------------------------------------------------------
  114. void
  115. CCounterApp::ChooseDocument()
  116. {
  117.     UDesktop::Deactivate();
  118.     SFTypeList            theTypeList = {kDocType};
  119.     StandardFileReply    theReply;
  120.     ::StandardGetFile( nil, 1, theTypeList, &theReply );
  121.     UDesktop::Activate();
  122.     if (theReply.sfGood) {                // if not canceled
  123.         SendAEOpenDoc(theReply.sfFile);    // send AppleEvent to open the document
  124.     }
  125. }
  126.  
  127. // ---------------------------------------------------------------------------------
  128. void
  129. CCounterApp::PrintDocument(FSSpec* inMacFSSpec )
  130. {
  131.     CCounterDocument* theDocument = new CCounterDocument(this, inMacFSSpec);
  132.     theDocument->DoPrint();
  133. }
  134.  
  135. // ---------------------------------------------------------------------------------
  136. void
  137. CCounterApp::ShowAboutBox()
  138. {
  139.     UDesktop::Deactivate();        // Alert will swallow Deactivate event
  140.  
  141.     StDialogHandler    theHandler(rAboutBox, this);
  142.     LWindow* theDialog = theHandler.GetDialog();    
  143.     theDialog->Show();
  144.     while (true) {
  145.         MessageT hitMessage = theHandler.DoDialog();
  146.         if (hitMessage == msg_OK) {
  147.             break;
  148.         }
  149.     }
  150.     UDesktop::Activate();
  151. }
  152.  
  153.